home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Utilities / SoundSwirl / sound.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-06  |  2.0 KB  |  94 lines  |  [TEXT/ALFA]

  1. /**************************
  2. ** sound.c
  3. **
  4. ** manages the sound-related functions
  5. ***************************/
  6.  
  7. #include "main.h"
  8. #include <SoundInput.h>
  9.  
  10. #define kAsynch TRUE
  11.  
  12. static long myInRefNum;
  13. static SPB  mySPB;
  14.  
  15.  
  16. /******************************************/
  17. void InitSound(void)
  18. {
  19. } /* InitSound() */
  20.  
  21.  
  22. /******************************************/
  23. /** KillSound() is called only when the  **/
  24. /** program is making its grand exit.    **/
  25. /******************************************/
  26. void KillSound(void)
  27. {
  28.     if (gListening)
  29.         SndListenStop();     /* turn off listening */
  30. } /* KillSound() */
  31.  
  32.  
  33. /******************************************/
  34. void SndListenBegin(void)
  35. {
  36.     OSErr myErr;
  37.  
  38.     myErr = SPBOpenDevice( NULL, siWritePermission, &myInRefNum);
  39.     
  40.     if (myErr == noErr)
  41.     {
  42.         mySPB.inRefNum = myInRefNum;
  43.         mySPB.count = 0;
  44.         mySPB.milliseconds = 0;
  45.         mySPB.bufferLength = 0;
  46.         mySPB.bufferPtr = NULL;     /* record forever, don't store it */
  47.         mySPB.completionRoutine = NULL;
  48.         mySPB.interruptRoutine = NULL;
  49.         mySPB.userLong = 0;
  50.         mySPB.error = noErr;
  51.         mySPB.unused1 = 0;
  52.         
  53.         myErr = SPBRecord( &mySPB, kAsynch);  /* record asynchronously */
  54.         
  55.         if (myErr != noErr)
  56.         {
  57.             Str255 s1;
  58.             NumToString( (long)myErr, s1);
  59.             Error("\pError during SPBRecord(): ", s1, "\p", "\p");
  60.             myErr = SPBCloseDevice( myInRefNum);
  61.         }
  62.     }
  63.     else
  64.         Error("\pCouldn't open the sound input device in InitSound().",
  65.                 "\p", "\p", "\p");
  66.     return;
  67. } /* SndListenBegin() */
  68.  
  69.  
  70. /******************************************/
  71. void SndListenStop(void)
  72. {
  73.     OSErr myErr;
  74.     myErr = SPBStopRecording( myInRefNum);
  75.     myErr = SPBCloseDevice(myInRefNum);
  76.     myInRefNum = 0;
  77.     return;
  78. } /* SndListenStop() */
  79.  
  80.  
  81. /******************************************/
  82. int FetchSndOffset(void)
  83. {
  84.     OSErr myErr;
  85.     short recStatus, meterLevel;
  86.     unsigned long totSamp, numSamp, totMsecs, numMsecs;
  87.     
  88.     myErr = SPBGetRecordingStatus( myInRefNum,
  89.             &recStatus, &meterLevel, &totSamp,
  90.             &numSamp, &totMsecs, &numMsecs);
  91.     return(meterLevel/2);
  92. } /* FetchSndOffset() */
  93.  
  94.